package dryven.view.engine.expression.nodelisters;

import java.util.ArrayList;
import java.util.Iterator;

import dryven.reflection.TypeRef;
import dryven.view.engine.expression.ExpressionNode;
import dryven.view.engine.expression.nodetypes.MapLookupNode;

public class MapNodeLister implements NodeLister {

	private ExpressionNodeFactory _factory;
	private TypeRef _type;
	
	public MapNodeLister(TypeRef type, ExpressionNodeFactory factory) {
		super();
		_factory = factory;
		_type = type;
	}

	@Override
	public boolean allowsWildChar() {
		return true;
	}

	@Override
	public ExpressionNode createWildCharNode(String name) {
		Iterator<TypeRef> types = _type.getGenericTypeParams().iterator();
		types.next();
		TypeRef componentType = types.next();
		return new MapLookupNode(_type, name, _factory.create(componentType));
	}

	@Override
	public Iterable<ExpressionNode> getChildNodes() {
		return new ArrayList<ExpressionNode>(0);
	}

}
